package br.com.dev.tcc.task;

import android.content.Context;
import android.os.AsyncTask;
import br.com.dev.tcc.bean.Apolice;
import br.com.dev.tcc.bean.DelegateListener;
import br.com.dev.tcc.bean.ResponseData;
import br.com.dev.tcc.connection.WSClient;

public class BuscaApoliceTask extends
		AsyncTask<Void, Void, ResponseData<Apolice>> {

	private String cpf;
	private String placa;
	private String cor;
	private DelegateListener<ResponseData<Apolice>> delegate;
	private Context context;

	public BuscaApoliceTask(Context context,
			DelegateListener<ResponseData<Apolice>> delegate, String cpf,
			String placa, String cor) {
		this.context = context;
		this.delegate = delegate;
		this.cpf = cpf;
		this.placa = placa;
		this.cor = cor;
	}

	@Override
	protected ResponseData<Apolice> doInBackground(Void... params) {

		WSClient client = new WSClient();

		try {
			return client.buscarApolice(context, cpf, placa, cor);
		} catch (Exception e) {
			return new ResponseData<Apolice>(false, e.getMessage(), null);
		}
	}

	@Override
	protected void onPostExecute(ResponseData<Apolice> result) {

		delegate.onDelegate(result);
	}
}
